package com.Ajava1801D.设计模式.代理模式.动态代理.CGLIB代理;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author: LCG
 * 作者: LCG
 * 日期: 2020/10/12  14:42
 * 描述:
 */
public class TestHandler2<T> implements MethodInterceptor {

    private Enhancer enhancer=new Enhancer();

    public T getObject(Class<?> classe){

        enhancer.setSuperclass(classe);
        enhancer.setCallback(this);

        return (T)enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("=============自己实现接口的业务============");

        return "8888888";
    }
}
